import mu.KotlinLogging
import org.apache.rocketmq.client.producer.DefaultMQProducer
import org.apache.rocketmq.common.message.Message
import java.text.SimpleDateFormat
import java.util.*

private val logger = KotlinLogging.logger {}
fun main() {
  val producer = DefaultMQProducer("Msg12")
  producer.namesrvAddr = "192.168.201.129:9876"
  try {
    producer.start()
    // 创建消息
    val message1 = Message("topic", "tags", "Hello RocketMQ 1".toByteArray())
    val message2 = Message("topic", "tags", "Hello RocketMQ 2".toByteArray())

    val currentTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())
    //val now = System.currentTimeMillis()
    message1.setDelayTimeSec(53*1000)
    message2.setDelayTimeSec(67*1000)
    logger.debug("发送时间：$currentTime-----发送内容：Hello RocketMQ 1")
    logger.debug("发送时间：$currentTime-----发送内容：Hello RocketMQ 2")
  } catch (e: Exception) {
    e.printStackTrace()
  } finally {
    producer.shutdown()
  }
}
